﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using JeffWilcox.Utilities.Silverlight;
using System.Windows.Browser;
using System.Threading;
using System.IO;
using System.Text;
using System.Runtime.Serialization.Json;
using System.Reflection;
using VkApi.DataTypes;

namespace VkApi
{
    public partial class VkApi
    {
        /// <summary>
        /// Gets the wiki-page inforamtion.
        /// </summary>
        /// <param name="pid">The wiki-page ID.</param>
        /// <param name="gid">The group ID where wiki-page is created.</param>
        /// <param name="need_html">The flag for wiki-page content inclusion. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Page information.</returns>
        public long Pages_Get(long pid, long gid, int? need_html, ApiCallback<Page> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("pid", pid.ToString()));
            list.Add(new Parameter("gid", gid.ToString()));
            if (need_html != null) list.Add(new Parameter("need_html", need_html.ToString()));
            return this.SendRequest("pages.get", callback, list.ToArray());
        }

        /// <summary>
        /// Saves the wiki-page text.
        /// </summary>
        /// <param name="pid">The wiki-page ID.</param>
        /// <param name="gid">The group ID.</param>
        /// <param name="text">The wiki-page text. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Page ID if success.</returns>
        public long Pages_Save(long pid, long gid, string text, ApiCallback<long> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("pid", pid.ToString()));
            list.Add(new Parameter("gid", gid.ToString()));
            if (text != null) list.Add(new Parameter("text", text));
            return this.SendRequest("pages.save", callback, list.ToArray());
        }

        /// <summary>
        /// Paves the read and edit access to the wiki-page.
        /// </summary>
        /// <param name="pid">The wiki-page ID.</param>
        /// <param name="gid">The group ID.</param>
        /// <param name="view">The view access. 2 - all, 1 - only group members, 0 - only group leaders.</param>
        /// <param name="edit">The edit access. 2 - all, 1 - only group members, 0 - only group leaders.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Page ID if success.</returns>
        public long Pages_SaveAccess(long pid, long gid, int view, int edit, ApiCallback<long> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("pid", pid.ToString()));
            list.Add(new Parameter("gid", gid.ToString()));
            list.Add(new Parameter("view", view.ToString()));
            list.Add(new Parameter("edit", edit.ToString()));            
            return this.SendRequest("pages.saveAccess", callback, list.ToArray());
        }

        /// <summary>
        /// Gets the previous version of wiki-page.
        /// </summary>
        /// <param name="pid">The wiki-page ID.</param>
        /// <param name="gid">The group ID where wiki-page is created.</param>
        /// <param name="need_html">The flag for wiki-page content inclusion. (unnecessary)</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Page information.</returns>
        public long Pages_GetVersion(long pid, long gid, int? need_html, ApiCallback<Page> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("pid", pid.ToString()));
            list.Add(new Parameter("gid", gid.ToString()));
            if (need_html != null) list.Add(new Parameter("need_html", need_html.ToString()));
            return this.SendRequest("pages.getVersion", callback, list.ToArray());
        }

        /// <summary>
        /// Gets the array of previous versions of the wiki-page.
        /// </summary>
        /// <param name="pid">The wiki-page ID.</param>
        /// <param name="gid">The group ID where wiki-page is created.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Array of pageVersion</returns>
        public long Pages_GetHistory(long pid, long gid, ApiCallback<PageVersion[]> callback)
        {
            List<Parameter> list = new List<Parameter>();
            list.Add(new Parameter("pid", pid.ToString()));
            list.Add(new Parameter("gid", gid.ToString()));            
            return this.SendRequest("pages.gethistory", callback, list.ToArray());
        }

        /// <summary>
        /// Gets the list of wiki-pages of the group.
        /// </summary>
        /// <param name="gid">The gid.</param>
        /// <param name="callback">The callback.</param>
        /// <returns>Array of Pages.</returns>
        public long Pages_GetTitles(long gid, ApiCallback<Page[]> callback)
        {
            List<Parameter> list = new List<Parameter>();          
            list.Add(new Parameter("gid", gid.ToString()));          
            return this.SendRequest("pages.getTitles", callback, list.ToArray());
        }



    }
}
